home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / DLOGManager 1.02 / Source Code / StandAloneMenu_v00.cp < prev    next >
Encoding:
Text File  |  1996-09-19  |  3.2 KB  |  172 lines  |  [TEXT/KAHL]

  1. /*** File: "StandAloneMenu_v00.c"
  2. *
  3. *    Versione 00. Del 25-09-94.
  4. *    Scritto da Cadili Francesco.
  5. *
  6. *    Gestisce i menu di "StandAlone_v00.c".
  7. ***********************************************/
  8. #include "StandAloneMenu_v00.h"
  9. #include <Dialogs.h>
  10.  
  11. /*****    Include standard        *****/
  12. /* MacHeaders Included */
  13.  
  14. #ifdef DEBUG_ANSI_STANDALONE
  15.     #include <stdio.h>
  16. #endif
  17. #include <Types.h>
  18. #include <Menus.h>
  19. #include <ToolUtils.h>
  20. #include <Desk.h>
  21. #include <Windows.h>
  22.  
  23. /*****    Include locali            *****/
  24.  
  25. // #include "MenuCall_v03.h"
  26. #include "ProcessNew_v00.h"
  27. #ifdef CONTROLLORISORSE
  28. #include "ControlloRisorse.h"
  29. #endif
  30.  
  31. /*****    Define macro            *****/
  32.  
  33. /*****    Define valori            *****/
  34.  
  35. #pragma segment StandAloneMenu
  36. #define MenuBarID 128
  37. #define kMenuNum 3
  38. enum {
  39.     fileMenuID = 128,
  40.     editMenuID,
  41.     appleMenuID
  42. };
  43.  
  44. enum {                // file menu item
  45.     newItem = 1,
  46.     quitItem = 3
  47. };
  48.  
  49. enum {
  50.     aboutItem = 1
  51. };
  52.  
  53. /*****    Typedef globali            *****/
  54.  
  55. /*****    Funzioni esterne        *****/
  56.  
  57. /*****    Variabili esterne        *****/
  58.  
  59. /*****    Variabili globali        *****/
  60.  
  61. /*****    Statiche globali        *****/
  62.  
  63. static Handle menuBar = NULL;
  64. static MenuHandle menuHdl[kMenuNum];        // contiene i puntatori agli elementi del menu (sono ordinati per posizione)
  65.  
  66. /*****    Function prototyping    *****/
  67.  
  68. static void     about(void);
  69.  
  70. /*** "SetUpMenus()"
  71. *
  72. *    Mette a posto i menu.
  73. *    Val OUTPUT:    true se tutto ok, false altrimenti.
  74. *
  75. *******************************************************/
  76. int SetUpMenus(void)
  77. {
  78.     menuBar = GetNewMBar(MenuBarID);
  79. #ifdef CONTROLLORISORSE
  80.     CaricaRisorsa('MBAR', MenuBarID);
  81. #endif
  82.  
  83.     if (menuBar != 0)
  84.     {
  85.         SetMenuBar(menuBar);
  86.         DrawMenuBar();
  87.         menuHdl[0] = GetMHandle(appleMenuID);
  88.         menuHdl[1] = GetMHandle(131);
  89.  
  90.         if (menuHdl[0] != NULL)
  91.             AddResMenu(menuHdl[0], 'DRVR');
  92.         if (menuHdl[1] != NULL)
  93.             AddResMenu(menuHdl[1], 'FONT');
  94.  
  95.         return(true);
  96.     }
  97.     else        // errore
  98.     {
  99.         #ifdef DEBUG_ANSI_STANDALONE
  100.             printf("errore nell'allocazione della barra dei menu");
  101.         #endif
  102.  
  103.         return(false);
  104.     }
  105. }
  106.  
  107. /*** "HandleMenu(mSelect)"
  108. *
  109. *    Gestisce la selezione dei menu. 
  110. *    Par INPUT: "mSelect" quello che MenuSelect() e MenuKey() ritornano
  111. *                    (la parte alta é il menu ID, la parte bassa è il menu item).
  112. *
  113. *************************************************************************************/
  114. int HandleMenu(long mSelect)
  115. {
  116.     int            menuID = HiWord(mSelect);
  117.     int            menuItem = LoWord(mSelect);    
  118.     int            computeNext = true;
  119.     
  120.     switch(menuID)
  121.     {
  122.          case appleMenuID:
  123.              if (menuHdl[0] != NULL)
  124.              {
  125.                  if (menuItem != aboutItem)
  126.                  {    // devo chiamare un desk accessory
  127.                      GrafPtr savePort;
  128.                      Str255 deskAccName;
  129.     
  130.                     GetPort(&savePort);
  131.                     GetItem(menuHdl[0], menuItem, deskAccName);
  132.                     OpenDeskAcc(deskAccName);
  133.                     SetPort(savePort);
  134.                 }
  135.                 else
  136.                 {        // ha scelto about StandAlone
  137.                     about();
  138.                 }
  139.             }
  140.             break;
  141.         case fileMenuID:
  142.             switch(menuItem)
  143.             {
  144.                 case newItem:
  145.                     ProcessNew();
  146.                     break;
  147.                 
  148.                 case quitItem:
  149.                     computeNext = false;
  150.                     break;
  151.             }
  152.             break;
  153.     }
  154.     return(computeNext);
  155. }
  156.  
  157. /*** CantOpen()
  158. *
  159. *    Errore nell'apertura del file delle risorse
  160. *
  161. *****************************************************/
  162. void about(void)
  163. {
  164.     short         itemHit;
  165.     DialogPtr    theDialog = GetNewDialog(130, NULL, (WindowPtr)-1L);
  166.     
  167.     ModalDialog (NULL, &itemHit);
  168.     DisposDialog(theDialog);
  169. }
  170. /* end CantOpen */
  171.  
  172.